<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- <script>
    /* 
    判断数据类型
    1. ===
    2. typeof
    3. instanceof
    4. constructor
    5. String.prototype.toString.call(obj)
    6. Array.isArray()
    */
    /* 
    // === 只能判断 undefined与null
    // typeof 能判断 number/string/boolean/undefined/function
              不能判断出null, 不能区别数组和对象    都是object
    // instanceof 能判断出对象的类型或原型链对象的类型
              能区别Array对象与Object对象
    */
    console.log(typeof null) // 'object'
    console.log(typeof []) // 'object'
    console.log([] instanceof Array) // true
    console.log([] instanceof Object) // true
    console.log({} instanceof Array) // false
    console.log([].constructor)  // Array函数
    console.log(Array.isArray([]))

    // Object.prototype.toString.call(obj)
    const obj = {}
    console.log(obj.toString())  // '[object Object]'    [object 类型名称]
    const arr = [1, 2]
    console.log(arr.toString()) // '1,2'  数组将Object原型上的toString进行了重写
    // 如何能让任意对象都能调用Object原型上的toString方法呢?
    
    console.log(Object.prototype.toString.call(arr))  // [object Array] 
    const type = Object.prototype.toString.call(arr).slice(8, -1)
    console.log(type) // 'Array'
 
    let a = 3
    console.log(a.constructor)  // Number函数    new Number(a).constructor
    a = null
    console.log(a.constructor)  // 报错  null和undefined没有包装类型
    // 为什么: 
  </script> -->

  <script>
    // Object.prototype.toString
    var obj = {m: 1}
    var obj2 = {n: 2}
    console.log(obj.toString()) // '[object Object]'
    console.log(obj.toString()) // '[object Object]'
    var arr = [1, 2]
    console.log(arr.toString()) // '1,2'   [object Array]

    function Fn() {
      
    }
    const fn = new Fn()
    console.log(fn.toString()) // [object Object]

    console.log(Object.prototype.toString.call(arr)) // [object Array]
    console.log(Object.prototype.toString.call(arr).slice(8, -1)) // Array

  </script>
</body>
</html>